/**
 * 路由导航工具类
 * 提供便捷的路由导航方法
 */

// 路由路径常量
export const ROUTES = {
  LOGIN: '/login',
  HOME: '/home',
  EXPERTS: '/experts', 
  CART: '/cart',
  USER: '/user'
};

// 创建导航函数工厂
const createNavigator = (navigate) => {
  return {
    // 导航到指定页面
    to: (path, options = {}) => {
      navigate(path, options);
    },

    // 导航到登录页面
    toLogin: (options = {}) => {
      navigate(ROUTES.LOGIN, options);
    },

    // 导航到首页
    toHome: (options = {}) => {
      navigate(ROUTES.HOME, options);
    },

    // 导航到专家页面
    toExperts: (options = {}) => {
      navigate(ROUTES.EXPERTS, options);
    },

    // 导航到订单页面
    toCart: (options = {}) => {
      navigate(ROUTES.CART, options);
    },

    // 导航到用户页面
    toUser: (options = {}) => {
      navigate(ROUTES.USER, options);
    },

    // 返回上一页
    back: (delta = 1) => {
      navigate(-delta);
    },

    // 替换当前页面
    replace: (path) => {
      navigate(path, { replace: true });
    },

    // 检查当前路径
    isCurrentPath: (path) => {
      return window.location.pathname === path;
    }
  };
};

// 导出导航函数工厂
export { createNavigator };
